import {http} from 'slash-web'
import {ApiResponse, ListResponse} from "slash-web";
import {PageQueryParam, SearchKeyQueryParam} from "slash-web";


export interface ${entityName}Response {
    #foreach($col in $fullColumnList)
    ${col.propertyName}:${col.tsType},
    #end
}
export interface Select${entityName}PageListQueryParam extends SearchKeyQueryParam {

}

/**
 * 分页查询列表
 * @param query
 */
export const select${entityName}PageList = (query: Select${entityName}PageListQueryParam): Promise<ListResponse<${entityName}Response>> => {
    console.log(query)
    return http.doGet('/${appCode}/${entityName}/selectPageList', query)
}
/**
 * 根据ID查询
 * @param id
 */
export const select${entityName}ById = (id: string|number): Promise<ApiResponse<${entityName}Response>> => {
    return http.doGet('/${appCode}/${entityName}/selectById', {id: id})
}

#foreach($col in $columnList)
#if ($col.unique == 1)
#set($upropertyName="${col.propertyName.substring(0, 1).toUpperCase()}${col.propertyName.substring(1)}")
/**
 * 根据${col.propertyName}查询
 * @param ${col.propertyName}
 */
export const select${entityName}By${upropertyName} = (${col.propertyName}: ${col.tsType}): Promise<ApiResponse<${entityName}Response>> => {
    return http.doGet('/${appCode}/${entityName}/selectBy${upropertyName}', {${col.propertyName}: ${col.propertyName}})
}
#end
#end

/**
 * 新增
 * @param id
 */
export const doSave${entityName} = (data: any): Promise<ApiResponse<boolean>> => {
    return http.doPost('/${appCode}/${entityName}/save', data)
}
/**
 * 修改
 * @param id
 */
export const doUpdate${entityName} = (data: any): Promise<ApiResponse<boolean>> => {
    return http.doPost('/${appCode}/${entityName}/update', data)
}
/**
 * 逻辑删除
 * @param id
 */
export const doLogicDelete${entityName} = (ids: Array<string | number> | number | string): Promise<ApiResponse<boolean>> => {
    let data = null;
    if (Array.isArray(ids)) {
        data = ids;
    } else {
        data = [ids];
    }
    return http.doPost('/${appCode}/${entityName}/logicDelete', data)
}
/**
 * 物理删除
 * @param id
 */
export const doDelete${entityName} = (ids: Array<string> | number | string): Promise<ApiResponse<boolean>> => {
    let data = null;
    if (Array.isArray(ids)) {
        data = ids;
    } else {
        data = [ids];
    }
    return http.doPost('/${appCode}/${entityName}/delete', data)
}

export default {
    select${entityName}PageList,
    select${entityName}ById,
    doDelete${entityName},
    doLogicDelete${entityName},
    doUpdate${entityName},
    doSave${entityName},
#foreach($col in $columnList)
#if ($col.unique == 1)
#set($upropertyName="${col.propertyName.substring(0, 1).toUpperCase()}${col.propertyName.substring(1)}")
select${entityName}By${upropertyName},
#end
#end
}
